class Solution {
public:
    int maxProfit(vector<int> &prices) {
        if (prices.size()<=1) return 0;
        int ret=0, m=prices[0];
        for (int i=1;i<prices.size();i++) {
            if (ret<prices[i]-m) ret=prices[i]-m;
            if (m>prices[i]) m=prices[i];
        }
        return ret;
    }
};
